#include"resource.h"
#include<Windows.h>
BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch(msg)
	{
	case WM_INITDIALOG:
		SetDlgItemText(hwnd,IDC_TEXT,"Nguyen Cao Cuong");
		SetDlgItemInt(hwnd,IDC_NUMBER,5,FALSE);
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDC_ADD:
			{
				BOOL bSucess;
				int nTimes=GetDlgItemInt(hwnd,IDC_NUMBER,&bSucess,FALSE);
				if(bSucess)
				{
					int len=GetWindowTextLength(GetDlgItem(hwnd,IDC_TEXT));
					if(len>0)
					{
						int i;
						char* buf;
						buf=(char*)GlobalAlloc(GPTR,len+1);
						GetDlgItemText(hwnd,IDC_TEXT,buf,len+1);
						for(i=0;i<nTimes;i++)
						{
							int index=SendDlgItemMessage(hwnd,IDC_LIST,LB_ADDSTRING,0,(LPARAM)buf);
							SendDlgItemMessage(hwnd,IDC_LIST,LB_SETITEMDATA,(WPARAM)index,(LPARAM)nTimes);
						}
						GlobalFree((HANDLE)buf);
					}
					
				}
			}
			break;
		}
		break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
		break;
	default:
		return FALSE;
	}
	return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdLine)
{
	return DialogBox(hInstance,MAKEINTRESOURCE(IDD_MAIN),NULL,DlgProc); 
}